package com.lx.algorithm.Tree;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-10-19 14:51:51
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-10-19     张李鑫                     1.0         1.0 Version
 */
public class TreeUtils {


    public static Node generateRandomBST(int maxLevel, int maxValue) {
        return generate(1, maxLevel, maxValue);
    }

    // for test
    public static Node generate(int level, int maxLevel, int maxValue) {
        if (level > maxLevel || Math.random() < 0.5) {
            return null;
        }
        int a=-1;
        Node head = new Node((int) (Math.random() * maxValue));
        head.left = generate(level + 1, maxLevel, a*maxValue);
        head.right = generate(level + 1, maxLevel, a*maxValue);
        return head;
    }
}
